home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
internet
/
yam_i_dodatki
/
pgpwithyam
/
source
/
selectkey.e
next >
Wrap
Text File
|
1997-06-18
|
6KB
|
274 lines
/**********************************************************\
* Filter pubkeys from pgp output and lets you select one *
* V1.0 by Michael Praschl *
\**********************************************************/
OPT PREPROCESS
-> PROC Module
MODULE 'tools/boopsi'
MODULE 'muimaster', 'libraries/mui'
MODULE 'utility/tagitem', 'utility/hooks'
MODULE 'intuition/classes', 'intuition/classusr'
MODULE 'libraries/gadtools'
MODULE 'tools/installhook'
-> ENDPROC
-> PROC #defines
-> ENDPROC
-> PROC Raises
RAISE "ARGS" IF ReadArgs()=NIL,
"FILE" IF Open()=NIL
-> ENDPROC
-> PROC Objekte
OBJECT rdargs
readargs,filename,public,
args[2]: ARRAY OF LONG
ENDOBJECT
OBJECT keylist
first: PTR TO keyentry
ENDOBJECT
OBJECT keyentry
next: PTR TO keyentry,
str: PTR TO CHAR
ENDOBJECT
OBJECT file
fh,
line: PTR TO CHAR
ENDOBJECT
-> ENDPROC
-> PROC Konstante
CONST KICKVERSION=39
-> ENDPROC
-> PROC Variable
DEF app,window,listview,list,
doublehook
-> ENDPROC
-> PROC Instanzen
DEF rdargs: PTR TO rdargs,
keylist: PTR TO keylist,
inf: PTR TO file
-> ENDPROC
/*
** Methoden
*/
PROC read(str) OF rdargs
self.readargs:=ReadArgs(str,self.args,NIL)
self.filename:=self.args[0]
self.public:=IF self.args[1]=NIL THEN 'pub' ELSE self.args[1]
ENDPROC
PROC end() OF rdargs
IF self.readargs THEN FreeArgs(self.readargs)
ENDPROC
CHAR '$VER: SelectKey 1.0 (18.6.97) by Michael Praschl'
PROC add(str) OF keylist
DEF ke: PTR TO keyentry
ke:=NewR(SIZEOF keyentry)
ke.str:=str
ke.next:=self.first
self.first:=ke
ENDPROC
PROC put2list(list) OF keylist
DEF ke: PTR TO keyentry
ke:=self.first
WHILE ke
domethod(list,[MUIM_List_InsertSingle,ke.str,MUIV_List_Insert_Top])
ke:=ke.next
ENDWHILE
ENDPROC
PROC end() OF keylist
DEF ke: PTR TO keyentry,
h
ke:=self.first
WHILE ke
IF ke.str THEN DisposeLink(ke.str)
h:=ke
ke:=ke.next
Dispose(h)
ENDWHILE
ENDPROC
PROC init(name,mode) OF file
self.line:=String(300)
IF self.line=NIL THEN Raise("MEM")
self.fh:=Open(name,mode)
ENDPROC
PROC readln() OF file
DEF ok
ok:=Fgets(self.fh,self.line,300)
ENDPROC IF ok THEN self.line ELSE FALSE
PROC getkeylines(list: PTR TO keylist,public) OF file
DEF keys: PTR TO CHAR,
ok
REPEAT
ok:=self.readln()
IF StrCmp(public,self.line,3)
IF (keys:=String(300))=NIL THEN Raise("MEM")
self.getuser(keys)
self.getid(keys)
list.add(keys)
ENDIF
UNTIL ok=FALSE
ENDPROC
PROC getid(str: PTR TO CHAR) OF file
DEF pos
IF (pos:=InStr(self.line,'/'))>=0
StrAdd(str,'0x')
StrAdd(str,self.line+pos+1,8)
ENDIF
ENDPROC
PROC getuser(str: PTR TO CHAR) OF file
DEF pos=0,lastwas=FALSE,anz=0 /* lastwas von TRUE auf FALSE -> anz++ */
REPEAT
IF self.line[pos]=" "
lastwas:=TRUE
ELSE
IF lastwas THEN anz++
lastwas:=FALSE
ENDIF
pos++
UNTIL (anz=3)
StrCopy(str,self.line+pos-1,StrLen(self.line+pos)) /* Trick */
/* ^ Start ^ ein Zeichen weniger wegen \n */
StrAdd(str,' ')
ENDPROC
PROC end() OF file
IF self.fh THEN Close(self.fh)
IF self.line THEN DisposeLink(self.line)
ENDPROC
/*
** Prozeduren
*/
PROC open_all()
NEW rdargs
rdargs.read('FILE/A,PUBLIC')
NEW inf.init(rdargs.filename,OLDFILE)
NEW keylist
inf.getkeylines(keylist,rdargs.public)
END inf
installhook(doublehook,{doublehook_proc})
IF (muimasterbase:=OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN))=NIL THEN Raise("MUIL")
app:= ApplicationObject,
MUIA_Application_Title,'Select a public key',
MUIA_Application_Version,'$VER: PubKey 1.0 (18.6.97)',
MUIA_Application_Copyright,' 1997, Michael Praschl',
MUIA_Application_Author,'Michael Praschl',
MUIA_Application_Description,'For selecting a public key',
MUIA_Application_Base,'PUBKEY',
SubWindow, window:=WindowObject,
MUIA_Window_Title, 'Select a public key...',
MUIA_Window_ID , "MAIN",
WindowContents, VGroup,
Child,listview:=ListviewObject,
MUIA_Listview_MultiSelect,MUIV_Listview_MultiSelect_Default,
MUIA_Listview_List,list:=ListObject,
InputListFrame,
MUIA_List_ConstructHook,MUIV_List_ConstructHook_String,
MUIA_List_DestructHook,MUIV_List_DestructHook_String,
End,
End,
End,
End,
End
IF app=NIL THEN Raise("APPL")
domethod(window,[MUIM_Notify,MUIA_Window_CloseRequest,MUI_TRUE,
app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit])
domethod(listview,[MUIM_Notify,MUIA_Listview_DoubleClick,MUI_TRUE,
list,2,MUIM_CallHook,doublehook])
domethod(listview,[MUIM_Notify,MUIA_Listview_DoubleClick,MUI_TRUE,
app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit])
keylist.put2list(list)
set(window,MUIA_Window_Open,MUI_TRUE)
ENDPROC
PROC close_all()
IF app THEN Mui_DisposeObject(app)
IF muimasterbase THEN CloseLibrary(muimasterbase)
END keylist
END rdargs
ENDPROC
PROC handle_all()
DEF signal, running=TRUE, result
WHILE running
result := domethod(app, [MUIM_Application_Input, {signal} ])
SELECT result
CASE MUIV_Application_ReturnID_Quit
running := FALSE
ENDSELECT
IF signal THEN Wait(signal)
ENDWHILE
ENDPROC
PROC doublehook_proc(hook,list,data)
DEF str,enum
enum:=MUIV_List_NextSelected_Start
REPEAT
domethod(list,[MUIM_List_NextSelected,{enum}])
IF (enum<>MUIV_List_NextSelected_End)
domethod(list,[MUIM_List_GetEntry,enum,{str}])
WriteF('\s\n',str+(StrLen(str)-10))
ENDIF
UNTIL (enum=MUIV_List_NextSelected_End)
ENDPROC
/*************** Main *************/
PROC main() HANDLE
IF KickVersion(KICKVERSION)=FALSE THEN Raise("KICK")
open_all()
handle_all()
EXCEPT DO
close_all()
IF exception
SELECT exception
CASE "MUIL"
WriteF('Failed to open \s.\n',MUIMASTER_NAME)
CASE "APPL"
WriteF('Failed to create application.\n')
CASE "KICK"
WriteF('Kickstart V\d++ required!\n',KICKVERSION)
CASE "NIL"
WriteF('NILpointer in line \d\n',exceptioninfo)
DEFAULT
WriteF('Exception ')
Write(stdout,{exception},4)
WriteF(' raised!\n')
ENDSELECT
ENDIF
ENDPROC